package com.ws.polymorphic;

import javax.crypto.spec.PSource;

/*
多态性的使用举例一：

 */
public class AnimalTest {
    public static void main(String[] args) {
        AnimalTest test = new AnimalTest();
        test.func(new Dog());

        test.func(new Cat());

        test.func(new Animal());
    }

    public void func(Animal animal) {
        animal.eat();
        animal.shout();
    }

//    public void func(Dog animal) {
//        animal.eat();
//        animal.shout();
//    }
//
//    public void func(Cat animal) {
//        animal.eat();
//        animal.shout();
//    }

}

class Animal {
    public void eat() {
        System.out.println("动物吃东西");
    }

    public void shout() {
        System.out.println("动物叫");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println("狗吃东西");
    }

    public void shout() {
        System.out.println("狗叫");
    }
}

class Cat extends Animal {
    public void eat() {
        System.out.println("猫吃东西");
    }

    public void shout() {
        System.out.println("猫叫");
    }
}

//举例二：
class Order {
    public void method(Object obj) {}
}

//举例三：
class Driver {

}
